package cn.dida.dao;

import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import cn.dida.model.Staff;
import cn.dida.model.Sysres;
import cn.dida.util.MD5Util;

/**
 * 账户管理 数据交互类
 * 
 * @author weiwei
 */
@Repository
public class RoleDao extends DaoBase {

	public List<Integer> getRoleResByCompanyId(Integer companyId) {

		String sql = "SELECT  res.id FROM pub_roleandpermission rs,company cp,sysres res,role r WHERE rs.role_id = cp.roleid AND rs.sysres_id = res.id AND rs.role_id = r.ID AND r.sta = 1 AND res.state = 1 AND cp.state = 1 AND cp.id = ?";
		List<Integer> result = jdbcTemplate.queryForList(sql, Integer.class, companyId);
		
		if (result.size() > 0) {
			return result;
		} else {
			return null;
		}
	}

	public List<Sysres> getRoleSysresByCompanyId(Integer companyId) {
		String sql = "SELECT  res.* FROM pub_roleandpermission rs,company cp,sysres res,role r WHERE rs.role_id = cp.roleid AND rs.sysres_id = res.id AND rs.role_id = r.ID AND r.sta = 1 AND res.state = 1 AND cp.state = 1 AND cp.id = ?";
		List<Sysres> result = jdbcTemplate.query(sql,  new BeanPropertyRowMapper<>(Sysres.class), companyId);
		
		if (result.size() > 0) {
			return result;
		} else {
			return null;
		}
	}

}
